package com.cloudOffice.config;

import jakarta.annotation.Resource;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class WeChatMpConfig {
	@Resource
	private WechatAccountConfig wechatAccountConfig;
	
	@Bean
	public WxMpConfigStorage wxMpConfigStorage() {
		WxMpDefaultConfigImpl wxMpConfigStorage = new WxMpDefaultConfigImpl();
		wxMpConfigStorage.setAppId(wechatAccountConfig.getMpAppId());
		wxMpConfigStorage.setSecret(wechatAccountConfig.getMpAppSecret());
		return wxMpConfigStorage;
	}
	
	@Bean
	public WxMpService wxMpService(WxMpConfigStorage wxMpConfigStorage) {
		WxMpService wxMpService = new WxMpServiceImpl();
		wxMpService.setWxMpConfigStorage(wxMpConfigStorage);
		return wxMpService;
	}
}
